import request from './request'
import { useUserStore } from '../store/modules/user'
import { CodeScanSet } from '../views/busic/base/module/coder_set/base/CodeScanning/types'

// 查询编码列表
export function getCodeList(data: object) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/getList',
    method: 'post',
    headers: token,
    data,
  })
}
// 查询编码列表详情
export function getInfo(id) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/getInfo/' + id,
    method: 'get',
    headers: token,
  })
}
// 批量激活编码
export function activCode(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/activCode',
    method: 'put',
    headers: token,
    data,
  })
}

// 批量删除编码
export function deleteCode(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/deleteCode',
    method: 'DELETE',
    headers: token,
    data,
  })
}
// 更改编码商品信息
export function codeGoodsBindingChange(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/codeGoodsBindingChange',
    method: 'put',
    headers: token,
    data,
  })
}
//获取产品下拉数据列表
export function productPageSelect(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/goods/select/productPageSelect',
    method: 'post',
    headers: token,
    data,
  })
}
//获取产品规格下拉数据列表
export function productSpecPageSelect(data, productId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/goods/select/productSpecPageSelect/' + productId,
    method: 'post',
    headers: token,
    data,
  })
}
//获取配件下拉数据列表
export function sparePageSelect(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/goods/select/sparePageSelect',
    method: 'post',
    headers: token,
    data,
  })
}
//获取配件规格下拉数据列表
export function spareSpecPageSelect(data, spareId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/goods/select/spareSpecPageSelect/' + spareId,
    method: 'post',
    headers: token,
    data,
  })
}
// 新增编码
export function addSave(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 编码历史工单列表接口
export function getHistoryOrderList(codeId: any, data: any) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/code/getHistoryOrder/${codeId}`,
    method: 'post',
    headers: token,
    data,
  })
}

// 编码商品变更记录(编码溯源)列表查询接口
export function codeGoodsChangeLog(data, code) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/codeGoodsChangeLog/getList/' + code,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取变更记录列表
export function userChangeList(data, codeId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/userChange/getList/' + codeId,
    method: 'post',
    headers: token,
    data,
  })
}
// 保存变更用户
export function saveChangeCodeUser(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/userChange/saveChangeCodeUser',
    method: 'post',
    headers: token,
    data,
  })
}
// 根据编码ID查询编码操作记录列表
export function loggetList(data, codeId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/log/getList/' + codeId,
    method: 'post',
    headers: token,
    data,
  })
}
// 批次编码列表
export function batchgetList(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/batch/getList',
    method: 'post',
    headers: token,
    data,
  })
}
// 保存编码关联用户登记
export function saveCodeRegister(data, codeId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/userRegister/saveCodeRegister/' + codeId,
    method: 'post',
    headers: token,
    data,
  })
}
// 获取用户下拉数据列表
export function selecUser(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/select/user/pageSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 批次ID获取批次编码详情
export function getDetail(id) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/batch/getDetail/' + id,
    method: 'get',
    headers: token,
  })
}
// 根据批次ID获取编码列表
export function getbatchCodeList(data, id) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/batch/getCodeList/' + id,
    method: 'post',
    headers: token,
    data,
  })
}
// 根据编码批次ID批量删除
export function deletebatchList(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/batch/',
    method: 'DELETE',
    headers: token,
    data,
  })
}

// 获取打印模版列表
export function printTemplateList(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/printTemplate/getList',
    method: 'post',
    headers: token,
    data,
  })
}
// 保存打印模版
export function savePrintTemplate(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/printTemplate/save',
    method: 'post',
    headers: token,
    data,
  })
}
// 根据模版ID获取模版组件详情
export function printTemplateGetDetail(id) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/printTemplate/getDetail/' + id,
    method: 'get',
    headers: token,
  })
}
// 批次编码下拉列表查询
export function codeBatchPageSelect(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/select/codeBatchPageSelect',
    method: 'post',
    headers: token,
    data,
  })
}
// 根据批次编码ID获取批次编码商品数据列表
export function codeBatchGoodsPageSelect(data, batchId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/select/codeBatchGoodsPageSelect/' + batchId,
    method: 'post',
    headers: token,
    data,
  })
}
// 批量删除打印模版
export function deletePrintTemplate(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/printTemplate/delete',
    method: 'DELETE',
    headers: token,
    data,
  })
}
// 根据模版ID批量启用或禁用打印模版
export function activeDeletePrintTemplate(data, status) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/printTemplate/getDetail',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}
// 批量更改编码商品信息
export function updateCodeGoods(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/batch/updateCodeGoods',
    method: 'put',
    headers: token,
    data,
  })
}
// 编码批次导出Excel
export function codeBatchExportExcel(excelType, batchId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/dataExport/codeBatchExportExcel/' + batchId,
    method: 'get',
    headers: token,
    params: { excelType: excelType },
    responseType: 'blob',
  })
}
//  编码批次导出文本Txt
export function codeBatchExportTxt(batchId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/dataExport/codeBatchExportTxt/' + batchId,
    method: 'get',
    headers: token,
  })
}
//获取打印模版数据
export function getPrintTemplateData(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/printTemplate/getPrintTemplateData',
    method: 'post',
    headers: token,
    data,
  })
}
// 变更用户登记地址
export function updateCodeRegisterAddress(data, codeId) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/code/userRegister/updateCodeRegisterAddress/' + codeId,
    method: 'put',
    headers: token,
    data,
  })
}
// 获取未登记商品编号
export function getNotRegisterCode(data) {
  let token = { 'access-token': useUserStore().token }
  return request({
    url: '/code/getNotRegisterCode',
    method: 'post',
    headers: token,
    data,
  })
}
// 获取未登记商品编号
export function getRegisterCode(data, userId) {
  let token = { 'access-token': useUserStore().token }
  return request({
    url: '/code/getRegisterCode/' + userId,
    method: 'post',
    headers: token,
    data,
  })
}
// 一物一码导出Excel
export function codeExportExcel(data) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/dataExport/codeExportExcel',
    method: 'post',
    headers: token,
    data,
    responseType: 'blob',
  })
}

// 获取编码扫码设置信息
export function getCodeScanSet() {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/set/getCodeScanSet',
    method: 'get',
    headers: token,
  })
}

// 保存编码扫码信息设置
export function saveCodeScanSet(data: Array<CodeScanSet>) {
  let token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/set/saveCodeScanSet',
    method: 'put',
    headers: token,
    data,
  })
}
